#include "Common.fx"
#include "Sampling.fx"

//--------------------------------------
struct a2v {
	float4 pos		: POSITION;
};

struct v2f {
	float4 pos		: POSITION;
	float2 uv		: TEXCOORD0;
};

//--------------------------------------
sampler g_InputSamp : register(s0);

const float2 g_InvInputSize : INV_INPUT_SIZE;

//--------------------------------------
v2f vsMain(a2v input) {
	
	v2f output;
	
	output.pos = input.pos;
	
	output.uv.x =  input.pos.x;
	output.uv.y = -input.pos.y;
	output.uv = output.uv * 0.5 + 0.5;
	
	return output;
}

//--------------------------------------
f2fb psMain(v2f input) {

	f2fb output;
	
	float2 baseTexcoord = input.uv + g_InvInputSize.y;
		
#if 1

	output.c0 = 1;
	
	for(int i=0; i<16; ++i)
		output.c0 = min(output.c0, tex2D(g_InputSamp, baseTexcoord + g_Uniform4x4[i] * g_InvInputSize.x) );
#else
	
	output.c0 = 0;
	
	for(int i=0; i<16; ++i)
		output.c0 += tex2D(g_InputSamp, baseTexcoord + g_Uniform4x4[i] * g_InvInputSize.x);
		
	output.c0 *= (1.0 / 16.0);
	
#endif
	
	return output;
}

//--------------------------------------
technique Dilate {

	pass {
	
		//ColorWriteEnable	= GREEN;
		AlphaBlendEnable	= false;
		AlphaTestEnable		= false;
		ZEnable				= false;
		ZWriteEnable		= false;
		
		VertexShader		= compile vs_3_0 vsMain();
		PixelShader			= compile ps_3_0 psMain();
	}
}

//--------------------------------------